package com.chinacoal.microservice.util;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author zhuliang
 * @version V1.0
 * @Description: 异常码管理类
 * @date 2020-11-06 14：19
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CodeMsg extends Exception {

    private int code;

    private String msg;

    //通用异常属性
    public static final CodeMsg Success = new CodeMsg(10000,"操作成功");
    public static final CodeMsg INVALID_TOKEN = new CodeMsg(10001, "无效TOKEN，请重新登录");
    public static final CodeMsg TOKEN_ABNORMAL_FORMAT = new CodeMsg(10002, "TOKEN格式校验异常");
    public static final CodeMsg REMOTE_LOGIN = new CodeMsg(10003, "此账号已在其他地方登录，请重新登录");
    public static final CodeMsg INCORRECT_USERNAME_OR_PASSWORD = new CodeMsg(10004, "登录失败，账号或密码错误");
    public static final CodeMsg NO_PRIVILEGES = new CodeMsg(10005,"没有权限访问");
    public static final CodeMsg GET_VERIFICATION_CODE_FAILED = new CodeMsg(10006, "获取验证码失败，请稍后在试");
    public static final CodeMsg VERIFICATION_CODE_ERROR = new CodeMsg(10007,"验证码错误");
    public static final CodeMsg EMAIL_ABNORMAL= new CodeMsg(10008,"邮箱格式校验异常");
    public static final CodeMsg PHONE_ABNORMAL= new CodeMsg(10009,"电话号码格式校验异常");
    public static final CodeMsg ID_CARD_ABNORMAL= new CodeMsg(10010,"身份证格式校验异常");
    public static final CodeMsg METHOD_NOT_SUPPORTED = new CodeMsg(10011,"不支持的请求类型");
    public static final CodeMsg NULL_ABNORMAL= new CodeMsg(10012,"空指针异常");
    public static final CodeMsg GET_INFORMATION_ABNORMAL = new CodeMsg(10013, "获取微信用户信息失败，请重新登录");
    public static final CodeMsg BIND_ERROR = new CodeMsg(10014,"参数校验异常: %s");
    public static final CodeMsg SERVER_ERROR = new CodeMsg(10015,"操作失败，服务端异常: %s");
    public static final CodeMsg NOT_FOUND = new CodeMsg(10016,"资源不存在");
    public static final CodeMsg IllegalArgumentException = new CodeMsg(10017,"参数转换异常");
    public static final CodeMsg SQL_ERROR = new CodeMsg(10018,"主键或唯一键约束失败");
    public static final CodeMsg NAME_OR_CODE_REPEAT = new CodeMsg(10019,"号码或编码已经被使用");
    public static final CodeMsg DATA_HAS_BEEN_USED = new CodeMsg(10020, "操作失败，此资源已被使用");
    public static final CodeMsg CONTRACT_TAKE_EFFECT = new CodeMsg(10021, "有合同已经生效过，不能删除");
    public static final CodeMsg ROOM_USING_TEMPLATE = new CodeMsg(10022, "当前有房间正在使用该模板，不可停止使用或删除");
    public static final CodeMsg CONNECTION_INVOICE_SERVER_ABNORMAL = new CodeMsg(10023, "连接发票服务器异常");
    public static final CodeMsg PERMISSION_DATE_EXCEPTION = new CodeMsg(10024, "权限数据异常");
    public static final CodeMsg HOUSE_TYPE_UPDATE_BUILDING = new CodeMsg(10025, "当前户型已被使用，暂不可更改楼宇");
    public static final CodeMsg WECHAT_PAY_ORDER_IS_ABNORMAL = new CodeMsg(10026, "微信支付，下单异常");
    public static final CodeMsg FAILED_TOOBTAIN_INFORMATION = new CodeMsg(10027, "获取信息失败，请刷新页面重新尝试");
    public static final CodeMsg LINE_ALREADY_IS_USE = new CodeMsg(10028, "此线路已经被使用");
    public static final CodeMsg SERIAL_NUMBER_ALREADY_EXISTS = new CodeMsg(10029, "此序列号已经存在");
    public static final CodeMsg FAILED_TO_OTAIN_DEVICE_INFORMATION = new CodeMsg(10030, "获取设备信息失败");
    public static final CodeMsg DEVICE_MODEL_DOES_NOT_MATCH = new CodeMsg(10031, "设备类型与序列号设备类型不符");
    public static final CodeMsg FAILED_TO_OBTAIN_DEVICE_TOKEN = new CodeMsg(10032, "获取第三方设备的token失败");
    public static final CodeMsg PAYMENT_EXCEPTION = new CodeMsg(10033, "支付异常，请联系工作人员");
    public static final CodeMsg ROOM_NUMBER_HAS_BEEN_USED = new CodeMsg(10034, "此房间号已经被本楼宇本楼层的其他房间所使用");
    public static final CodeMsg CONTRACT_START_TIME_OVERLAPPING = new CodeMsg(10035, "与已生效或待生效的合同时间重叠，请确认合同开始时间");
    public static final CodeMsg ASSEMBLY_CHECK_DATA_ABNORMAL = new CodeMsg(10036, "组装微信查询订单数据异常");
    public static final CodeMsg OPEN_INVOICE_FAILURE = new CodeMsg(10037, "开票异常");
    public static final CodeMsg CANNOT_DOUBLE_INVOICE = new CodeMsg(10038, "不能重复去开取发票");
    public static final CodeMsg ONLINE_INVOICEC_CANNOT_IN_OFFLINE_MODE = new CodeMsg(10039, "线下模式不能开取线上发票");
    public static final CodeMsg COST_SHEET_NOT_METER_READING_OR_REVIEW = new CodeMsg(10040, "费用单还未抄表或审核");
    public static final CodeMsg OFFLINE_INVOICEC_CANNOT_IN_ONLINE_MODE = new CodeMsg(10041, "线上模式不能开取线下发票");
    public static final CodeMsg USER_DELETE_ERROR = new CodeMsg(10042,"该账号不存在");
    public static final CodeMsg INCORRECT_PASSWORD = new CodeMsg(10043, "原密码校验错误");
    public static final CodeMsg NO_EXPENSE_ENTRY_THIS_MONTH = new CodeMsg(10044, "本房间本月没有抄表,不能获取月行度");

    public CodeMsg fillArgs(Object...args) {
        int code = this.code;
        String msg = String.format(this.msg,args);
        return new CodeMsg(code,msg);
    }

    @Override
    public String toString() {
        return "CodeMsg{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
